/*
 * Copyright 2004-2005 asoft
 * 本软件及其所有拷贝的名称，与光盘上或本软件中注明的公司同在。
 * 本软件及文档享有版权，并受国家版权法及国际协约条款的保护。
 * 您不可以从本软件中去掉其版权声明；并保证为本软件的拷贝（本部或部分）* 复制版权声明。
 * 您同意制止以任何形式非法拷贝本软件及文档。
 * 版权信息参见：
 *      http://www.asoft.cn/licenses
 */

package com.asoft.common.base.web.view;

import java.text.DecimalFormat;

import com.asoft.common.base.define.FontLayOut;

/**
 *  记录明细区
 *  如横表:新增,修改,删除等()
 *
 */

public class Item
{
        private double dv;
        
        /** 名称 */
        private String text;

        /** js函数 */
        private String onClickJSFunc;

        private String onMouseOverJS;

        private boolean printed = true;

        private String itemExt = "";

        private int xLayOut; // 水平布局
        
        private boolean hidden =false;
        
        private boolean bold;
        
        // 文本长度
        private int length;

        public Item()
        {
                this.xLayOut = FontLayOut.LEFT;
        }

        public Item(String text)
        {
                this.text = text;
                this.xLayOut = FontLayOut.LEFT;
        }

        public Item(String text,String onClickJSFunc)
        {
                this.text = text;
                this.onClickJSFunc = onClickJSFunc;
                this.xLayOut = FontLayOut.LEFT;
        }

        public Item(String text,int xLayOut)
        {
                this.text = text;
                this.xLayOut = xLayOut;
        }

        public Item(String text,
                    String onClickJSFunc,
                    int xLayOut)
        {
                this.text = text;
                this.onClickJSFunc = onClickJSFunc;
                this.xLayOut = xLayOut;
        }

        // int 默认水平居右
        public Item(int text)
        {
                this.text = Integer.toString(text);
                this.xLayOut = FontLayOut.RIGHT;
        }

        public Item(int text,
                    String onClickJSFunc)
        {
                this.text = Integer.toString(text);
                this.onClickJSFunc = onClickJSFunc;
                this.xLayOut = FontLayOut.RIGHT;
        }

        // long 默认水平居右
        public Item(long text)
        {
                this.text = Long.toString(text);
                this.xLayOut = FontLayOut.RIGHT;
        }

        public Item(long text,
                    String onClickJSFunc)
        {
                this.text = Long.toString(text);
                this.onClickJSFunc = onClickJSFunc;
                this.xLayOut = FontLayOut.RIGHT;
        }

        // double 默认水平居右
        public Item(double dv)
        {
                this.text = "尚未格式化double";
                this.dv = dv;
                this.xLayOut = FontLayOut.RIGHT;
        }

        public Item(double text,
                    String onClickJSFunc)
        {
                this.text = Double.toString(text);
                this.onClickJSFunc = onClickJSFunc;
                this.xLayOut = FontLayOut.RIGHT;
        }

        /**
         * @return 返回 hidden。
         */
        public boolean isHidden()
        {
                return hidden;
        }

        /**
         * @param hidden 要设置的 hidden。
         */
        public Item setHidden(boolean hidden)
        {
                this.hidden = hidden;
                if(this.isHidden())
                {
                        this.printed = false;
                }
                return this;
        }
        
        /**
         * @return 返回 bold。
         */
        public boolean isBold()
        {
                return bold;
        }

        /**
         * @param bold 要设置的 bold。
         */
        public Item setBold(boolean bold)
        {
                this.bold = bold;
                return this;
        }

        public String getText()
        {
                return this.text;
        }

        public String getOnClickJSFunc()
        {
                return this.onClickJSFunc;
        }

        public int getXLayOut()
        {
                return this.xLayOut;
        }

        public Item setXLayOut(int xLayOut)
        {
                this.xLayOut = xLayOut;
                return this;
        }
        
        public Item left()
        {
                this.xLayOut = FontLayOut.LEFT;
                return this;
        }
        
        public Item center()
        {
                this.xLayOut = FontLayOut.CENTER;
                return this;
        }
        
        public Item right()
        {
                this.xLayOut = FontLayOut.RIGHT;
                return this;
        }
        

        public Item setOnClickJSFunc(String onClickJSFunc)
        {
                this.onClickJSFunc = onClickJSFunc;
                return this;
        }

        public Item setText(String text)
        {
                this.text = text;
                return this;
        }

        public String getItemExt()
        {
                return this.itemExt;
        }

        public Item setItemExt(String itemExt)
        {
                this.itemExt = itemExt;
                return this;
        }

        public String getOnMouseOverJS()
        {
                if(this.onMouseOverJS == null)
                        return "";
                else
                        return this.onMouseOverJS;
        }

        public Item setOnMouseOverJS(String onMouseOverJS)
        {
                this.onMouseOverJS = onMouseOverJS;
                return this;
        }

        public boolean getPrinted()
        {
                return this.printed;
        }

        public Item setPrinted(boolean printed)
        {
                this.printed = printed;
                return this;
        }
        
        public Item setLength(int length)
        {
                this.length = length;
                return this;
        }
        
        public Item setDoubleFormatPar(String par)
        {
                DecimalFormat df = new DecimalFormat(par);
                this.text = df.format(this.dv);
                return this;
        }
        
        public int getLength()
        {
                if(this.length == 0)
                {
                        return this.text.length();
                }
                else
                {
                        return this.length;
                }
        }
        
        public String getText4Html()
        {
                if(this.isBold())
                {
                        return "<b>" + this.text + "</b>";
                }
                else
                {
                        return this.text;
                }
        }
}
